package com.clanteam.javaking.fic;

/*
 * 
 */

public class LookupValue {

	final static long zero = 4, one = 3, two = 3, three = 5, four = 4,five = 4; // basic numbers
	final static long six = 3, seven = 5, eight = 5, nine = 4, ten = 3,thirteen = 8; // basic numbers & 13
	final static long fifteen = 7, eleven = 6, twelve = 6, teen = 4; // lower teens
	final static long twenty = 6, thirty = 6, eighty = 6, ninety = 6; // 6 counters
	final static long fifty = 5, sixty = 5, forty = 5; // 5 counters
	final static long seventy = 7, hundred = 7; // 7 counters

	public long power;
	public long multiplier;

	public LookupValue(long power, long multiplier) {
		this.power = power;
		this.multiplier = multiplier;
	}

	public long getValue() {
		/*
		 * Returns the value stored in LookupValue
		 */
		long ret = multiplier * (long) Math.pow(10, power);
		return ret;
	}

	public long getCharacterCount() {
		long tempPower = power % 3;
		long tempValue = multiplier * (long) Math.pow(10, tempPower);
		if ((tempValue == 0) && (tempPower != 0)) {
			return 0;
		}
		long numChars = lookup(tempValue);

		if (numChars == -1) {
			throw new RuntimeException("lookup failed. power [" + power
					+ "], tempPower [" + tempPower + "], multiplier["
					+ multiplier + "], tempValue [" + tempValue + "] ");
		}
		return numChars;
	}
	
	

	public static String lookupSpelling(long number) {
		switch ((int)number) {
		case 0:
			return "zero";
		case 1:
			return "one";
		case 2:
			return "two";
		case 3:
			return "three";
		case 4:
			return "four";
		case 5:
			return "five";
		case 6:
			return "six";
		case 7:
			return "seven";
		case 8:
			return "eight";
		case 9:
			return "nine";
		case 10:
			return "ten";
		case 11:
			return "eleven";
		case 12:
			return "twelve";
		case 13:
			return "thirteen";
		case 14:
			return "fourteen";
		case 15:
			return "fifteen";
		case 16:
			return "sixteen";
		case 17:
			return "seventeen";
		case 18:
			return "eighteen";
		case 19:
			return "nineteen";
		case 20:
			return "twenty";
		case 30:
			return "thirty";
		case 40:
			return "forty";
		case 50:
			return "fifty";
		case 60:
			return "sixty";
		case 70:
			return "seventy";
		case 80:
			return "eighty";
		case 90:
			return "ninety";
		case 100:
			return "one hundred";
		case 200:
			return "two hundred";
		case 300:
			return "three hundred";
		case 400:
			return "four hundred";
		case 500:
			return "five hundred";
		case 600:
			return "six hundred";
		case 700:
			return "seven hundred";
		case 800:
			return "eight hundred";
		case 900:
			return "nine hundred";
		default:
			return null;
		}
	}
	
	public String getSpelling() {
		long number = getValue();
		return lookupSpelling(number);
	}

	public static long lookup(long number) {
		long input = number;
		switch (((int) input)) {
		case 0:
			return 0;
		case 1:
			return one;
		case 2:
			return two;
		case 3:
			return three;
		case 4:
			return four;
		case 5:
			return five;
		case 6:
			return six;
		case 7:
			return seven;
		case 8:
			return eight;
		case 9:
			return nine;
		case 10:
			return ten;
		case 11:
			return eleven;
		case 12:
			return twelve;
		case 13:
			return thirteen;
		case 14:
			return four + teen;
		case 15:
			return fifteen;
		case 16:
			return six + teen;
		case 17:
			return seven + teen;
		case 18:
			return eight + teen - 1;
		case 19:
			return nine + teen;
		case 20:
			return twenty;
		case 30:
			return thirty;
		case 40:
			return forty;
		case 50:
			return fifty;
		case 60:
			return sixty;
		case 70:
			return seventy;
		case 80:
			return eighty;
		case 90:
			return ninety;
		case 100:
			return one + hundred;
		case 200:
			return two + hundred;
		case 300:
			return three + hundred;
		case 400:
			return four + hundred;
		case 500:
			return five + hundred;
		case 600:
			return six + hundred;
		case 700:
			return seven + hundred;
		case 800:
			return eight + hundred;
		case 900:
			return nine + hundred;
		default:
			return -1;
		}
	}
}
